import 'virtual:windi-base.css';
import 'virtual:windi-components.css';
import '/@/design/index.less';
import 'virtual:windi-utilities.css';
// Register icon sprite
import 'virtual:svg-icons-register';
import App from './App.vue';
import { createApp } from 'vue';
import { initAppConfigStore } from '/@/logics/initAppConfig';
import { setupErrorHandle } from '/@/logics/error-handle';
import { router, setupRouter } from '/@/router';
import { setupRouterGuard } from '/@/router/guard';
import { setupStore } from '/@/store';
import { setupGlobDirectives } from '/@/directives';
import { setupI18n } from '/@/locales/setupI18n';
import { registerGlobComp } from '/@/components/registerGlobComp';

import { isDevMode } from './utils/env';

if (isDevMode()) {
  import('ant-design-vue/es/style');
}

async function bootstrap() {
  const app = createApp(App);
  console.log('1.main.ts->bootstrap 初始化应用', app);

  setupStore(app);
  //console.log('2.main.ts->setupStore 配置存储');

  initAppConfigStore();
  //console.log('3.main.ts->initAppConfigStore 初始化内部系统配置');

  registerGlobComp(app);
  //console.log('4.main.ts->registerGlobComp 注册全局组件');

  await setupI18n(app);
  //console.log('5.main.ts->setupI18n 配置多语言');

  setupRouter(app);
  //console.log('6.main.ts->setupRouter 配置路由');

  setupRouterGuard(router);
  //console.log('7.main.ts->setupRouterGuard 配置路由守卫');

  setupGlobDirectives(app);
  //console.log('8.main.ts->setupGlobDirectives 注册全局指令');
  
  setupErrorHandle(app);
  //console.log('9.main.ts->setupErrorHandle 配置全局错误处理');

  // https://next.router.vuejs.org/api/#isready
  // await router.isReady();

  app.mount('#app');
}

bootstrap();
